import request from "@/utils/request"
import type {
  category1Response,
  category2Response,
  category3Response,
  categoryListResponse,
  SaveAttrApiParams,
} from "./model/attrModel"

enum Api {
  getcategory1 = "/admin/product/getCategory1",
  getcategory2 = "/admin/product/getCategory2", // get，params为id
  getcategory3 = "/admin/product/getCategory3", // get，params为id
  getCategoryList = "/admin/product/attrInfoList", // /{category1Id}/{category2Id}/{category3Id}
  updateAttr = "/admin/product/saveAttrInfo",
  removeAttr = "/admin/product/deleteAttr",
}

// 获取一级分类数据
export const getgetcategory1Api = () => {
  return request.get<any, category1Response>(Api.getcategory1)
}

// 获取二级分类数据
export const getgetcategory2Api = (id: number) => {
  return request.get<any, category2Response>(`${Api.getcategory2}/${id}`)
}
// 获取三级分类数据
export const getgetcategory3Api = (id: number) => {
  return request.get<any, category3Response>(`${Api.getcategory3}/${id}`)
}
// 获取分类属性列表
export const getCategoryListApi = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return request.get<any, categoryListResponse>(
    `${Api.getCategoryList}/${category1Id}/${category2Id}/${category3Id}`
  )
}

// 修改属性
export const updateAttrApi = (data: SaveAttrApiParams) => {
  return request.post<any, null>(`${Api.updateAttr}`, { data })
}

// 删除属性
export const removeAttrApi = (id: number) => {
  return request.delete<any, null>(`${Api.removeAttr}/${id}`)
}
